#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

class Solution {
public:
    double findMaxAverage(const vector<int>& nums, int k) {
        int total = 0, i = 0;
        for(; i < k; i++){
            total += nums[i];
        }
        // max = total * 1.0 / k;
        
        int max = total;
        for(;i < nums.size();i++){
            total -= nums[i - k];
            total += nums[i];
            if(total > max){
                max = total;
            }
        }
        return max * 1.0 / k;
    }
};

int main(int argc, char const *argv[])
{
    /* code */
    Solution sol;
    cout << sol.findMaxAverage({0, 4, 0, 3, 2}, 1) << endl; 
    return 0;
}
